ioemu: Attempt to setup tap interface up to 3 times.
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Thu, 24 May 2007 14:25:35 +0000 (15:25 +0100)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Thu, 24 May 2007 14:25:35 +0000 (15:25 +0100)
As there is a (small) chance that vl.c:tap_open() fails (due to some
sort of race-condition in the Linux kernel, which is noted as a bug in
the source .../net/core/dev.c), we should attempt it again a couple of
times if it doesn't succeed on the first attempt. I think three times
in total is sufficient to avoid the problem.

If tap_open() fails, qemu-dm will exit, which means that the domain
dies - which is not such a good thing when attempting to restore a saved
domain [of course, it would be even worse if it started, but didn't
have networking - because there may not be a way to shut it down
cleanly without network].

Signed-off-by: Mats Petersson <mats.petersson@amd.com>
tools/ioemu/vl.c

index 32d5163b4e4f791b38b200ad09770ff62e9c58f1..b1fe292d9bd3b7ed24ee8e84381789c0cc021c95 100644 (file)
@@ -3399,7 +3399,7 @@ static int tap_open(char *ifname, int ifname_size)
 static int tap_open(char *ifname, int ifname_size)
 {
     struct ifreq ifr;
-    int fd, ret;
+    int fd, ret, retries = 0;
     
     fd = open("/dev/net/tun", O_RDWR);
     if (fd < 0) {
@@ -3412,7 +3412,9 @@ static int tap_open(char *ifname, int ifname_size)
         pstrcpy(ifr.ifr_name, IFNAMSIZ, ifname);
     else
         pstrcpy(ifr.ifr_name, IFNAMSIZ, "tap%d");
-    ret = ioctl(fd, TUNSETIFF, (void *) &ifr);
+    do {
+        ret = ioctl(fd, TUNSETIFF, (void *) &ifr);
+    } while ((ret != 0) && (retries++ < 3));
     if (ret != 0) {
         fprintf(stderr, "warning: could not configure /dev/net/tun: no virtual network emulation\n");
         close(fd);